package com.suxin.logger.handler;

import com.suxin.logger.Level;
import com.suxin.logger.LogManager;
import com.suxin.logger.LogRecord;
import com.suxin.logger.filter.Filter;
import com.suxin.logger.formatter.Formatter;

/**
 * @author Tang
 * @classname Handler
 * @description [  ]
 * @date 2022/4/26 22:09
 */
public abstract class Handler {

    protected static LogManager logManager = LogManager.getLogManager();

    private Formatter formatter;
    private Filter filter;

    private Level level;

    /**
     * publish
     * @param lr
     */
    public abstract void publish(LogRecord lr);

    /**
     * flush
     */
    public abstract void flush();

    /**
     * close
     */
    public abstract void close();


    public Formatter getFormatter() {
        return formatter;
    }

    public void setFormatter(Formatter formatter) {
        this.formatter = formatter;
    }

    public Filter getFilter() {
        return filter;
    }

    public void setFilter(Filter filter) {
        this.filter = filter;
    }

    public Level getLevel() {
        return level;
    }

    public void setLevel(Level level) {
        this.level = level;
    }

    protected boolean isLoggable(LogRecord lr){
        return lr.getLevel().getValue() <= this.level.getValue();
    }
}
